package dao;

import common.User;

import java.io.FileInputStream;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;

public class CheckIsFriend2 {
    public int checkIsFriend(User u) throws ClassNotFoundException, SQLException, IOException {
        Connection conn = null;
        ResultSet res = null;

        Properties info = new Properties();
        info.load(new FileInputStream("src\\sql.properties"));
        String user = info.getProperty("user");
        String password = info.getProperty("password");
        String Driver = info.getProperty("Driver");
        String url = info.getProperty("url");
        //注册驱动
        Class.forName(Driver);
        //获取连接
        conn = DriverManager.getConnection(url, user, password);
        String sql = "select * from friendlist where user_id = ? and friend_id = ?";
        PreparedStatement presta = conn.prepareStatement(sql);
        presta.setString(1, u.getFriendid());
        presta.setString(2, u.getId());
        res = presta.executeQuery();
        if (res.next()) {
            return res.getInt("statement");
        } else {
            return -1;
        }
    }
}
